import request from '@/utils/request'

// 模拟数据
const mockData = {
  // 产品标准列表
  standardList: [
    {
      id: 1,
      productId: 1,
      standardId: 1,
      code: "STD-001",
      name: "产品质量检测标准",
      typeName: "检测标准",
      version: "V1.0",
      condition: "适用于所有产品",
      isPrimary: 1,
      createTime: new Date()
    },
    {
      id: 2,
      productId: 1,
      standardId: 2,
      code: "STD-002",
      name: "包装标准",
      typeName: "包装标准",
      version: "V1.2",
      condition: "适用于常温产品",
      isPrimary: 0,
      createTime: new Date()
    }
  ],
  // 标准详情
  standardDetail: {
    id: 1,
    productId: 1,
    standardId: 1,
    condition: "适用于所有产品",
    isPrimary: 1,
    parameters: [
      {
        name: "重量",
        value: "100",
        unit: "g"
      },
      {
        name: "长度",
        value: "50",
        unit: "mm"
      }
    ],
    remark: "测试标准"
  }
};

// 使用模拟数据响应
const useMockData = true;

// 查询产品关联的标准列表
export function listProductStandard(productId) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      data: mockData.standardList
    });
  }
  
  return request({
    url: '/qep/productStandard/list',
    method: 'get',
    params: { productId: productId }
  })
}

// 查询产品关联标准详细
export function getProductStandard(id) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      data: mockData.standardDetail
    });
  }
  
  return request({
    url: '/qep/productStandard/' + id,
    method: 'get'
  })
}

// 新增产品关联标准
export function addProductStandard(data) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/productStandard',
    method: 'post',
    data: data
  })
}

// 修改产品关联标准
export function updateProductStandard(data) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/productStandard',
    method: 'put',
    data: data
  })
}

// 删除产品关联标准
export function delProductStandard(id) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/productStandard/' + id,
    method: 'delete'
  })
}

// 批量删除产品关联标准
export function delProductStandards(ids) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/productStandard/' + ids,
    method: 'delete'
  })
}

// 设置为主标准
export function setPrimaryStandard(id, productId) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/productStandard/setPrimary',
    method: 'put',
    data: {
      id: id,
      productId: productId
    }
  })
} 